﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using RSSReader.MobileClient.ViewModel;

namespace RSSReader.MobileClient
{
    public partial class ActionPage : PhoneApplicationPage
    {
        private FeedViewModel Feedvm;
        private ArticleViewModel Articlevm;

        public ActionPage()
        {
            InitializeComponent();
        }

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            
            

            if (NavigationContext.QueryString.ContainsKey("DeleteFeed"))
            {
                Feedvm = new FeedViewModel();
                Feedvm.DelFeed(NavigationContext.QueryString["DeleteFeed"], App.UserId);
                NavigationService.Navigate(new Uri("/FeedSelectorPage.xaml",UriKind.Relative));
            }
            else if (NavigationContext.QueryString.ContainsKey("FavArticle"))
            {
                NavigationService.RemoveBackEntry();
                Articlevm = new ArticleViewModel();
                bool iFa;
                if (NavigationContext.QueryString["FavArticle"] == "True")
                    iFa = false;
                else
                    iFa = true;
                string title = NavigationContext.QueryString["title"];
                string body = NavigationContext.QueryString["body"];
                string link = NavigationContext.QueryString["link"];
                string sourceurl = NavigationContext.QueryString["sourceurl"];
                Articlevm.FavArticle(title, body, link, sourceurl, iFa);
                NavigationService.Navigate(new Uri("/ArticlePage.xaml?Action=1&LocLink=" + NavigationContext.QueryString["sourceurl"], UriKind.Relative));
            }
            else if (NavigationContext.QueryString.ContainsKey("ReadArticle"))
            {

            }
        }
    }
}